var t = getApp();

Page({
    data: {
        Height: "",
        tempshare: null,
        username: "用户昵称",
        signName: "个性签名",
        category: [],
        carousel: [],
        goodsListData: [],
        ads: [],
        bannerData: [],
        userImg: "",
        shop_logo: "",
        shop_name: "",
        shop_id: "",
        bgImg: "",
        isCategory: !1,
        amout: !0,
        index2: 1,
        other: "",
        content: "",
        show: !0,
        classifyBol: !0,
        goods_template: "01",
        tempData: [ {
            id: "M1491471961972",
            temp: "showsearch",
            params: {
                placeholder: "",
                style: "style2",
                color: "#000",
                bgcolor: "#FFF",
                bordercolor: "#fa1f24",
                searchurl: "",
                uniacid: "6"
            },
            data: "",
            other: "",
            content: ""
        } ],
        oftemp: !1,
        dftempData: !1,
        follow: !1,
        isfollow: !0,
        havaShop: !1,
        shopData: {},
        shop_idKey: "",
        iPnoneBottomBol: !1,
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(o) {
        this.getiPnoneBottom(), wx.createSelectorQuery().select(".li").boundingClientRect(function(t) {
            console.log(t);
        }).exec(), o.mid && t._setMid(o.mid), o.shop_id && this.setData({
            shop_idKey: o.shop_id,
            shop_id: o.shop_id
        }), this.getMicroShop(), this.getGooglistStyle();
    },
    getGooglistStyle: function() {
        var t = wx.getStorageSync("yz_basic_info");
        t && 1 === t.home.item.is_decorate && (0 != t.home.item.ViewSet.goodsList.is_default ? this.setData({
            "goods_template.names": t.home.item.ViewSet.goodsList.code.substring(9)
        }) : this.setData({
            classifyBol: !1
        }), !this.data.goods_template || "02" != this.data.goods_template.names && "03" != this.data.goods_template.names || this.setData({
            classifyBol: !1
        }));
    },
    getiPnoneBottom: function() {
        try {
            wx.getStorageSync("iPhoneBottom") && this.setData({
                iPnoneBottomBol: !0
            });
        } catch (t) {}
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    getMoreData: function() {
        var o = this;
        if (this.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            var a = this.data.page + 1;
            this.setData({
                page: a
            });
            var e = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.MicroShopByShare.get-goods");
            e += "&page=" + this.data.page, e += "&shop_id=" + this.data.shop_id, t._getNetWork({
                url: e,
                success: function(t) {
                    var a = t.data;
                    if (1 == a.result) {
                        var e = a.data.goods_list.data;
                        o.data.isLoadMore = !0, o.setData({
                            goodsListData: o.data.goodsListData.concat(e)
                        });
                    } else o.data.page = o.data.page - 1, o.data.isLoadMore = !1;
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onShareTimeline: function() {
        if (this.data.shop_id) {
            var t = wx.getStorageSync("yz_uid"), o = "";
            return t && (o = t), {
                query: "shop_id=" + this.data.shop_id + "&mid=" + o
            };
        }
        wx.showToast({
            title: "分享信息正在加载",
            icon: "none",
            duration: 1500
        });
    },
    onShareAppMessage: function(t) {
        if (t && "menu" === t.from) {
            if (this.data.shop_id) {
                var o = wx.getStorageSync("yz_uid"), a = "";
                o && (a = o);
                var e = this.data;
                return {
                    title: e.username,
                    path: "/packageC/microshop/micro_shop_share_home/micro_shop_share_home?shop_id=" + e.shop_id + "&mid=" + a
                };
            }
            wx.showToast({
                title: "分享信息正在加载",
                icon: "none",
                duration: 1500
            });
        }
    },
    imgHeight: function(t) {
        var o = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        this.setData({
            Height: o
        });
    },
    getMicroShop: function() {
        var o = this;
        o.data.isLoadMore = !1;
        var a = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.default");
        t._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (o.setData({
                    isLoadMore: !0,
                    shopData: e.data
                }), o.setMicroShopUserInfo(e.data), o.setBannerData(e.data), o.setCategoryData(e.data), 
                o.setData({
                    shop_id: e.data.shop_id
                }), o.getGoodList(), o.storeShopId(e.data.shop_id), t._setshopid(e.data.shop_id)) : wx.showModal({
                    title: "提示",
                    content: "您暂时无微店,点击确定申请？",
                    success: function(t) {
                        t.confirm ? wx.navigateTo({
                            url: "/packageC/microshop/microShop_apply/microShop_apply"
                        }) : t.cancel && wx.navigateBack({
                            delta: 1
                        });
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getGoodList: function() {
        var o = this, a = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.MicroShopByShare.get-goods");
        t._postNetWork({
            url: a,
            data: {
                shop_id: this.data.shop_id,
                mid: wx.getStorageSync("yz_uid")
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? o.setGoodsData(a) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    setMicroShopUserInfo: function(t) {
        this.setData({
            username: t.nickname,
            signName: t.signature,
            shop_logo: t.shop_logo,
            shop_name: t.shop_name,
            bgImg: 0 != t.shop_background && t.shop_background,
            userImg: t.shop_avatar
        });
    },
    setBannerData: function(t) {
        this.setData({
            bannerData: t.carousel
        });
    },
    setCategoryData: function(o) {
        if (t._isTextEmpty(o.category) || 0 == o.category.length) this.setData({
            isCategory: !1
        }); else {
            this.setData({
                isCategory: !0
            });
            this.setData({
                category: this.chunk(o.category, 8)
            }), console.log(this.data.category);
        }
    },
    chunk: function(t, o) {
        for (var a = [], e = 0, s = t.length; e < s; e += o) a.push(t.slice(e, e + o));
        return a;
    },
    setGoodsData: function(t) {
        this.setData({
            goodsListData: t.data.goods_list.data
        }), this.data.total_page = t.data.goods_list.last_page, this.data.page = t.data.goods_list.current_page;
    },
    storeShopId: function(t) {
        wx.setStorage({
            key: "setShopId",
            data: t
        });
    },
    replaceShopId: function(o) {
        (t._isTextEmpty(this.data.shop_idKey) || this.data.shop_idKey != o) && wx.redirectTo({
            url: "/packageC/microshop/microShop_home/microShop_home?shop_id=" + o
        });
    },
    goimgurl: function(t) {
        var o = t.currentTarget.dataset.link;
        try {
            wx.navigateTo({
                url: o
            });
        } catch (t) {
            wx.showToast({
                title: "链接设置错误",
                icon: "none",
                duration: 2e3
            });
        }
    },
    gohome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    gocart: function() {
        wx.reLaunch({
            url: "/packageG/pages/buy/cart_v2/cart_v2"
        });
    },
    gomember: function() {
        wx.reLaunch({
            url: "/packageG/member_v2/member_v2"
        });
    },
    gomicroShopShareCategory: function() {
        wx.navigateTo({
            url: "/packageC/microshop/micro_shop_share_category/micro_shop_share_category?shop_id=" + this.data.shop_id
        });
    },
    gomicroShopShopKeeperCenter: function() {
        wx.navigateTo({
            url: "/packageC/microshop/microShop_ShopKeeperCenter/microShop_ShopKeeperCenter?shop_id=" + this.data.shop_id
        });
    }
});